package com.zntg.utils;

import java.io.File;
import java.io.IOException;

/**
 * @program: spring_clould_v1-master
 * @description:
 * @author: zhengyunfei
 * @create: 2018-12-10 11:40
 **/
public class FileUtils {
    public static boolean  mkdir(String filePath){
        boolean flag=false;
        File file =new File(filePath);
        //如果文件夹不存在则创建
        if  (!file .exists()  && !file .isDirectory())
        {
            //System.out.println("//不存在");
            flag=false;
            file .mkdir();
        } else
        {
            //System.out.println("//目录存在");
            flag=true;
        }
        return flag;
    }
    public static boolean  createParentDir(String filePath){
        boolean flag=false;
        File saveFile= new File(filePath);
        File parentFile=saveFile.getParentFile();
        if(!parentFile.exists()&&!parentFile.isDirectory()){
            parentFile.mkdirs();
            flag=true;
        }
        //创建文件
       /* if(!saveFile.exists())
        {
            try {
                saveFile.createNewFile();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }*/
        return flag;
    }
    public static boolean  createFile(String filePath){
        boolean flag=false;
        File saveFile= new File(filePath);
        File parentFile=saveFile.getParentFile();
        if(!parentFile.exists()&&!parentFile.isDirectory()){
            parentFile.mkdirs();
            flag=true;
        }
        //创建文件
        if(!saveFile.exists())
        {
            try {
                saveFile.createNewFile();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        return flag;
    }
}
